<?php

require_once("../../../init.php");
//header("Content-Type:text/html; charset=UTF-8");
$contents = file_get_contents("../../../welcome.php");
//$contents = str_replace(HH, "<br/>", $contents);
if (startWith($contents, "<?php")) {
    if (isset($_GET["recover"])) {
        $contents = substr($contents, stripos($contents, "?>") + 2);
        $contents = ltrim($contents);
        if ($contents) {
            file_put_contents("../../../welcome.php", $contents);
        }
        echo "还原成功!显示welcome页面!<br/>";
        echo "<a href=\"" . Gc::$url_base . "tools/tools/web/deploy.php\">线上部署</a><br/>";
    } else {
        echo "<a href=\"" . Gc::$url_base . "tools/tools/web/deploy.php?recover=yes\">还原</a>【至开发导航首页】<br>";
    }
    echo "<a href=\"" . Gc::$url_base . "\" target='_blank'>返回首页</a><br/>";
} else {
    $redirect_head = <<<REDIRECT_HEAD
<?php
require_once("Gc.php");
require_once("core/include/common.php");
if (!contains( \$_SERVER['HTTP_HOST'], array("127.0.0.1", "localhost") )) {
    header("location:" . Gc::\$url_base . "index.php?go=" . Gc::\$appName . ".index.index");
    die();
}
?>

REDIRECT_HEAD;

    $contents = $redirect_head . $contents;
    file_put_contents("../../../welcome.php", $contents);
    //echo $contents;
    echo "部署成功，服务器域名访问不再显示welcome页面,直接跳转到" . Gc::$site_name . "首页<br/>[本地域名:localhost或者Ip:127.0.0.1仍然显示]<br/>";
    echo "<a href=\"" . Gc::$url_base . "tools/tools/web/deploy.php?recover=yes\">还原</a>【至开发导航首页】<br>";
    echo "<a href=\"" . Gc::$url_base . "\" target='_blank'>返回首页</a><br/>";
}
